package com.yunchi.schedule;

import cn.hutool.core.date.DateUtil;
import com.yunchi.service.MonitorService;
import com.yunchi.utils.MonitorPropertiesUtils;
import com.yunchi.utils.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: Crazer
 * @Date: 2023/7/4 10:22
 * @version: 1.0.0
 * @Description: 定时执行心跳监控任务
 */
@EnableScheduling
@Component
public class MonitorTask {
    private static final Logger logger = LoggerFactory.getLogger(MonitorTask.class);

    @Autowired
    private MonitorService monitorService;

    @Scheduled(cron = "${monitor.task.cron}")
    public void monitor() {
        // 当前时间字符串，格式：yyyy-MM-dd HH:mm:ss
        String opeationTime = DateUtil.now();
        boolean flag = monitorService.monitor();
        if (flag) {
            logger.info("运行时间：{}，合成成功", opeationTime);
        } else {
            logger.error("运行时间：{}，合成失败", opeationTime);
        }
    }

    @Scheduled(cron = "${monitor.task.cronCDisk}")
    public void monitorCDisk() {
        SystemUtils.monitorCDisk(MonitorPropertiesUtils.SMS_URL, MonitorPropertiesUtils.SMS_PHONE);
    }
}
